const path = require("path")
const HtmlWebpack = require("html-webpack-plugin")

module.exports = {
    mode: "development",//生产模式
    entry: path.resolve(__dirname, '../src/index.js'),//入口
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, '../dist'),
    },
    plugins: [
        new HtmlWebpack({
            template: './public/index.html',
            title: "模板",
            favicon: path.resolve(__dirname, '../public/favicon.ico')//设置浏览器页签图标
        })
    ],
    resolve: {
        extensions: ['.tsx', '.ts', '.js'],
        alias: {
            '@views': path.resolve(__dirname, '../src')
        }
    },
    module: {
        rules: [
            {
                test: /\.css$/i,
                use: ["style-loader", "css-loader"],
            },
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/,
            },
            {
                test: /\.js|jsx$/, exclude: /node_modules/,//在配置babel-loader的时候一定要加上exclude，否则项目会报错跑不起来
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: [
                            ['@babel/preset-react', { runtime: 'automatic' }]
                        ]
                    }
                }
            }
        ]
    },
}